package BookManagement.domain;
import lombok.*;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Page {
    private int pageSize;
    private int pageCount;
    private int pageCurrent;
    private int start;
    private int rowCount;

    public Page(String pageNo,int pageSize,int total){
        this.pageSize=pageSize;
        if(pageNo==null||pageNo.trim().length()==0){
            this.pageCurrent=1;
        }else {
            this.pageCurrent=Integer.parseInt(pageNo);
        }
        this.rowCount=total;
        if(this.rowCount%this.pageSize==0){
            this.pageCount=this.rowCount/this.pageSize;
        }else {
            this.pageCount=this.rowCount/this.pageSize+1;
        }
        if (this.pageCurrent>this.pageCount){
            this.pageCurrent=this.pageCount;
        }
        if(this.pageCurrent<1)this.pageCurrent=1;

        this.start=(this.pageCurrent-1)*this.pageSize;
    }
}
